

class ScorePanel{
    score = 0;
    level = 1;

    // 设置最高等级
    maxlevel:number;

    // 设置多少分加一级
    setupLevel:number



    // 分数和等级所在元素，在构造函数中进行初始化
    scoreEle: HTMLElement;
    levelEle: HTMLElement;

    // 设置最高等级默认为10级别，步长为2
    constructor(maxlevel:number =10, setupLevel:number = 2) {
        this.scoreEle = document.getElementById("score")!
        this.levelEle = document.getElementById("level")!
        this.maxlevel = maxlevel;
        this.setupLevel = setupLevel;
    }

    // 设置加分
    addScore(){
        this.scoreEle.innerText = ++this.score +'';
        if (this.score % this.setupLevel == 0){
                    this.addpanel()
        }
    }

    //设置等级
    addpanel(){
        if(this.level<this.maxlevel){
            this.levelEle.innerText = ++this.level + '';
        }
    }

}

export default ScorePanel;

// const  sp = new ScorePanel(100,10)
// for(let i=0; i< 200;i++){
//    sp.addScore()
// }